package com.cat.responsibility;

/**
 * @author cat
 * @version 2025/5/27 12:16
 * @description 抽象处理者类
 * @since JDK17
 */

public abstract class Handler {
    protected final static int NUM_ONE = 1;
    protected final static int NUM_THREE = 3;
    protected final static int NUM_SEVEN = 7;

    // 该领导处理的请假天数区间
    private int numStart;
    private int numEnd;

    // 声明后续者
    private Handler nextHandler;

    public Handler(int numStart) {
        this.numStart = numStart;
    }

    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    // 处理请假条的方法
    protected abstract void handleLeave(LeaveRequest leave);

    public Handler() {
    }

    // 提交请假条
    public final void submit(LeaveRequest leave) {
        // 该领导进行审批
        this.handleLeave(leave);
        if (this.nextHandler != null && leave.getDays() >  this.numEnd) {
            this.nextHandler.submit(leave); // 下一级去处理
        } else {
            System.out.println("流程结束");
        }
    }
}
